<?php
	include_once('DAOEventos.php');

	$iIdEvento = $_GET['evento'];
	$iError = $_GET['error'];
	$oDaoEvento = new DAOEventos;
	$oEvento = $oDaoEvento->getEventoByID($iIdEvento);
	$aHorarios = $oEvento[0]->getHorarios();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Administracion Eventos</title>
<meta name="viewport" content="width=device-width" />
<link href="../css/view_mobile.css" type="text/css" rel="stylesheet" media="only screen and (min-width: 0px) and (max-width: 350px)"/>
<link href="../css/view.css" type="text/css" rel="stylesheet" media="only screen and (min-width: 351px)" />
<script src="../script/eventos.js" type="text/javascript"></script>
</head>

<body onBlur="self.focus()">
<div id="adminEvent">
    <div id="error"><?php if($iError == 1) echo "No se Admite Campos Vac&iacute;os" ?></div>
    <form action="updateOrDelete.php" name="nuevoEvento" id="nuevoEvento" method="post">
    <fieldset>
    	<legend>Administracion de Evento</legend>
        <label>Sala</label><br />
        <select name="sala">
        	<option value="0"> Selecccionar sala... </option>
            <?php 
				foreach($aSalas as $oSala){
					echo '<option value="'.$oSala->getIdSala().'"> '.htmlentities($oSala->getNombre()).' </option>';	
				}
			?>
        </select><br />
	<label for="evento">Nombre del Evento:</label><br /><input type="text" name="evento" id="evento" value="<?php echo $oEvento[0]->getNombreEvento() ?>"/><br />
     <label for="equipo">Equipo:</label><br /><textarea name="equipo" id="equipo"><?php echo $oEvento[0]->getEquipo();?></textarea><br />
    <input type="hidden" value="<?php echo $oEvento[0]->getIdEvento(); ?>" name="iEvento" />
    <div class="inline"><label>Fecha de Inicio:</label><br /><span id="fechaIni"><?php echo $aHorarios[0]->getFechaInicio(); ?></span></div><br />
    <input type="hidden" value="<?php echo $aHorarios[0]->getFechaInicio();?>" name="fechaInicio" />
    <?php 
		$aFechaPartes= split('-',$aHorarios[0]->getFechaFin());
		$iAnio = $aFechaPartes[0];
		$iMes = $aFechaPartes[1];
		$iDia = $aFechaPartes[2];
	?>
    <div class="inline">
    <label for="fechaFin">Fecha de Culminaci&oacute;n</label><br />
    <select name="anioFin" id="anioFin">
    						<?php
								$sSelected = "";
								for($numOptionsAnio=2011;$numOptionsAnio<2026;$numOptionsAnio++){
									if($iAnio == $numOptionsAnio)
										$sSelected = 'selected="selected"';
									echo '<option value="'.$numOptionsAnio.'" '.$sSelected.' > '.$numOptionsAnio.' </option>';
									$sSelected = "";
								}	
							?>
    </select>
    <select name="mesFin" onchange="changeDays(document.getElementById('anioFin').value,this.value);">
    						<?php 
								for($numOptionsMes=1;$numOptionsMes<13;$numOptionsMes++){
									if($iMes == $numOptionsMes)
										$sSelected = 'selected="selected"';
									
									if($numOptionsMes<10)
											echo '<option value="0'.$numOptionsMes.'" '.$sSelected.'> 0'.$numOptionsMes.' </option>';
									else
										echo '<option value="'.$numOptionsMes.'" '.$sSelected.'> '.$numOptionsMes.' </option>';
									$sSelected = "";
								}
							?>
    </select>
    <span id="dias">
    <select name="diaFin">
    						<?php 
								for($numOptionsDia=1;$numOptionsDia<32;$numOptionsDia++){
									if($iDia == $numOptionsDia)
										$sSelected = 'selected="selected"';
									
									if($numOptionsDia<10)
										echo '<option value="0'.$numOptionsDia.'" '.$sSelected.'> 0'.$numOptionsDia.' </option>';
									else
										echo '<option value="'.$numOptionsDia.'" '.$sSelected.'> '.$numOptionsDia.' </option>';
									$sSelected = "";
								}
							?>
    </select></span></div><br />
    <?php 
		$aHoraInicioPartes= split(':',$aHorarios[0]->getHoraInicio());
		$aHoraFinPartes= split(':',$aHorarios[0]->getHoraFin());
	?>
	<div class="inline"><label>Horario:</label><br /><select name="horaInicio">
    						<?php
								$bIsSelected = false; 
								for($numOptions=0;$numOptions<24;$numOptions++){
									if($aHoraInicioPartes[0] == $numOptions){
										$sSelected = 'selected="selected"';
										if($aHoraInicioPartes[1] == '30'){
											$bIsSelected = true;
										}
									}
									
									if($numOptions<10){
										if($bIsSelected)
											echo '<option value="0'.$numOptions.':00"> 0'.$numOptions.':00 </option><option value="0'.$numOptions.':30"'.$sSelected.'> 0'.$numOptions.':30 </option>';
										else
											echo '<option value="0'.$numOptions.':00" '.$sSelected.'> 0'.$numOptions.':00 </option><option value="0'.$numOptions.':30"> 0'.$numOptions.':30 </option>';
									}else{
										if($bIsSelected)
											echo '<option value="'.$numOptions.':00"> '.$numOptions.':00 </option><option value="'.$numOptions.':30"'.$sSelected.'> '.$numOptions.':30 </option>';
										else
											echo '<option value="'.$numOptions.':00" '.$sSelected.'> '.$numOptions.':00 </option><option value="'.$numOptions.':30"> '.$numOptions.':30 </option>';
									}
									$sSelected = "";
									$bIsSelected = false; 
								}
							?>
                            </select> a
    						<select name="horaFin">
                            	<?php
								$bIsSelected = false;  
								for($numOptions=0;$numOptions<24;$numOptions++){
									if($aHoraFinPartes[0] == $numOptions){
										$sSelected = 'selected="selected"';
										if($aHoraFinPartes[1] == '30')
											$bIsSelected = true;
									}
									
									if($numOptions<10){
										if($bIsSelected)
											echo '<option value="0'.$numOptions.':00"> 0'.$numOptions.':00 </option><option value="0'.$numOptions.':30"'.$sSelected.'> 0'.$numOptions.':30 </option>';
										else
											echo '<option value="0'.$numOptions.':00" '.$sSelected.'> 0'.$numOptions.':00 </option><option value="0'.$numOptions.':30"> 0'.$numOptions.':30 </option>';
									}else{
										if($bIsSelected)
											echo '<option value="'.$numOptions.':00"> '.$numOptions.':00 </option><option value="'.$numOptions.':30"'.$sSelected.'> '.$numOptions.':30 </option>';
										else
											echo '<option value="'.$numOptions.':00" '.$sSelected.'> '.$numOptions.':00 </option><option value="'.$numOptions.':30"> '.$numOptions.':30 </option>';
									}
									$sSelected = "";
									$bIsSelected = false; 
								}
							?>
                            </select></div><br />
    <label>Coordinador:</label><br /><input type="text" name="solicitante" id="solicitante" value="<?php echo $oEvento[0]->getSolicitante() ?>"/><br />
    <label>Correo:</label><br /><input type="text" name="correo" id="correo" value="<?php echo $oEvento[0]->getCorreo() ?>"/><br />
    <label>Telefono:</label><br /><input type="text" name="telefono" id="telefono" value="<?php echo $oEvento[0]->getTelefono() ?>"/>
    <input type="hidden" value="<?php echo $oEvento[0]->getIdSala() ?>" name="sala" /><br />
    <?php
		$iAnioToday = date('Y');
		$iMesToday = date('m');
		$iDayToday = date('d'); 
		if($iAnio >= $iAnioToday && $iMes >= $iMesToday && $iDia >= $iDayToday){ 
	?>
    <input type="submit" name="actualizar" value="Actualizar" class="botonSubmit" />
    <input type="submit" name="eliminar" value="Eliminar"  class="botonSubmit"/>
    <?php }?>
    </fieldset>
    </form>
</div>
</body>
</html>